package org.moore.view;

import org.moore.utils.Data;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

import static org.moore.utils.Button.getjButton;

// 欢迎界面注册界面组件类
public class RegisterJLabel extends JLabel {
	// 创建随机玩家id
    private final Random random = new Random();
    // 随机玩家id(8位随机UID)
    private final int id = random.nextInt(899999) + 100000;
    // 创建账号输入框
    private final JTextField accText = new JTextField();
    // 创建密码输入框
    private final JPasswordField pwdText = new JPasswordField();
    // 创建重复密码输入框
    private final JPasswordField pwdAgainText = new JPasswordField();
    // 创建昵称输入框
    private final JTextField nameText = new JTextField();
    // 创建注册按钮
    private final JButton yesButton;
    // 创建返回按钮
    private final JButton backButton;
    // 创建字体
    private final Font font = new Font("微软雅黑",Font.BOLD,30);

    public RegisterJLabel() {
        // 设置账号输入框并添加
        accText.setBounds(250,155,200,50);
        accText.setFont(font);
        this.add(accText);
        // 设置密码输入框并添加
        pwdText.setBounds(250,230,200,50);
        pwdText.setFont(font);
        this.add(pwdText);
        // 设置重复密码输入框并添加
        pwdAgainText.setBounds(250,300,200,50);
        pwdAgainText.setFont(font);
        this.add(pwdAgainText);
        // 设置昵称输入框并添加
        nameText.setBounds(250,375,200,50);
        nameText.setFont(font);
        this.add(nameText);
        // 设置登录按钮
        yesButton = getjButton(Data.BUTTON_ICON, Data.FONT);
        yesButton.setBounds(120,480,150,150);
        yesButton.setText("注册");
        this.add(yesButton);
        // 设置返回按钮
        backButton = getjButton(Data.BUTTON_ICON, Data.FONT);
        backButton.setBounds(320,480,150,150);
        backButton.setText("返回");
        this.add(backButton);
    }
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        // 使用g2d绘制以修复抗锯齿
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        // 绘制背景
        g2d.drawImage(Data.WELCOME_BACKGROUND,0,0,this.getWidth(),this.getHeight(),null);
        // 绘制标题图片
        g2d.drawImage(Data.TITLE_IMAGE, 480, 50, 1000, 130, null);
        // 绘制用户id
        g2d.drawString("您的用户ID为" + id + "，请牢记该id!",190,130);
        // 设置字体
        g2d.setFont(font);
        // 绘制提示文字
        g2d.drawString("用户注册",230,100);
        // 绘制账号文字
        g2d.drawString("账       号",100,190);
        // 绘制密码文字
        g2d.drawString("密       码",100,265);
        // 绘制重复密码文字
        g2d.drawString("重复密码",100,335);
        // 绘制昵称文字
        g2d.drawString("昵       称",100,410);
    }

    public int getId() {
        return id;
    }

    public JTextField getAccText() {
        return accText;
    }

    public JPasswordField getPwdText() {
        return pwdText;
    }

    public JPasswordField getPwdAgainText() {
        return pwdAgainText;
    }

    public JTextField getNameText() {
        return nameText;
    }

    public JButton getYesButton() {
        return yesButton;
    }

    public JButton getBackButton() {
        return backButton;
    }

}
